export namespace StDate {

}

export class StDate {
    readonly date: Date;
    constructor(val?: string | number | Date) {
        if (typeof val != "undefined") {
            this.date = new Date(val);
        } else {
            this.date = new Date();
        }
    }
    get fullYear(): number {
        return this.date.getFullYear();
    }
    get month(): number {
        return this.date.getMonth() + 1;
    }
    get day(): number {
        return this.date.getDate();
    }
    get dayInWeek(): number {
        return this.date.getDay();
    }
    get hour(): number {
        return this.date.getHours();
    }
    get min(): number {
        return this.date.getMinutes();
    }
    get minute(): number {
        return this.min;
    }
    get sec(): number {
        return this.date.getSeconds();
    }
    get second(): number {
        return this.sec;
    }
    get mSec(): number {
        return this.date.getMilliseconds();
    }
    get milliseconds(): number {
        return this.mSec;
    }
    get timestamp(): number {
        return this.date.getDate();
    }
    public toDayStart(): StDate {
        let str = `${this.fullYear}-${this.month}-${this.day}`;
        return new StDate(str);
    }
    static now(): StDate {
        return new StDate();
    }
    public pad(param: string | number) {
        let str: string;
        if (typeof param == "number") {
            str = param.toString();
        } else {
            str = param;
        }
        return str.padStart(2, '0');
    }
    public timeString() {
        return this.date.toLocaleDateString();
    }
    public toLocaleString() {
        return this.date.toLocaleString();
    }
}